/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gephi.statistics.spi;

import java.util.HashMap;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.Node;

/**
 *
 * @author lczgywzyy
 */
public class LGraph {

//    private LVertex vertexList[]; // list of vertices
    private HashMap<Integer, LVertex> vertexList = new HashMap<Integer, LVertex>();
//    private int adjMat[][]; // adjacency matrix

//    private int nVerts;
    private static int MAX_VERTS = -1; // n个点

    int i = 0;
    int j = 0;

    public HashMap<Integer, LVertex> getVertexList() {
        return vertexList;
    }

    public HashMap<Integer, HashMap<Integer, Integer>> getAdjMat() {
//        return adjMat;
        return LSparse_Matrix.getInstance().getMatrix();
    }

    public int getN() {
        return MAX_VERTS;
    }

    public LGraph(Graph hgraph, int index) {
//        adjMat = new int[MAX_VERTS][MAX_VERTS]; // 邻接矩阵
        MAX_VERTS = hgraph.getNodeCount();
//        vertexList = new LVertex[MAX_VERTS]; // 顶点数组
//        nVerts = 0;

        for (Edge e : hgraph.getEdges()) {
            addEdge(Integer.parseInt(("" + e.getSource().getId()).trim()), Integer.parseInt(("" + e.getTarget().getId()).trim()));
        }
        for (Node n : hgraph.getNodes()) {
            addVertex(Integer.parseInt("" + n.getId()));
        }
//        for (i = 0; i < MAX_VERTS; i++) {
//            for (j = 0; j < MAX_VERTS; j++) {
////                adjMat[i][j] = 0;
//                LSparse_Matrix.getInstance().setValue(i, j, 0);
//            }
//        }

//        addVertex(0);
//        addVertex(1);
//        addVertex(2);
//        addVertex(3);
//        addVertex(9);
//        addVertex(5);
//        addVertex(7);
//        
//        addEdge(0, 1);
//        addEdge(0, 2);
//        addEdge(1, 4);
//        addEdge(2, 0);
//        addEdge(2, 5);
//        addEdge(3, 0);
//        addEdge(3, 2);
//        addEdge(3, 3);
//        addEdge(4, 1);
//        addEdge(4, 2);
//        addEdge(5, 7);
//        addEdge(7, 3);
        switch (index) {
            case 0:
                break;
            case 1:
                delEdge(4, 2);
                break;
            default:
                break;
        }
    }

    private void delEdge(int start, int end) {
//        adjMat[start][end] = 0;
        LSparse_Matrix.getInstance().setValue(start, end, 0);
    }

    private void addEdge(int start, int end) {// 有向图，添加边
//        adjMat[start][end] = 1;
        LSparse_Matrix.getInstance().setValue(start, end, 1);
    }

    public void addVertex(int lab) {
        //        vertexList[nVerts++] = new LVertex(lab);// 添加点
        vertexList.put(lab, new LVertex("" + lab));
    }

    public String displayVertex(int i) {
//        return vertexList[i].getLabel();
        return vertexList.get(i).getLabel();
    }

    public boolean displayVertexVisited(int i) {
//        return vertexList[i].WasVisited();
        return vertexList.get(i).WasVisited();
    }

    public void printGraph() {
//        for (i = 0; i < MAX_VERTS; i++) {
//            System.out.print("第" + displayVertex(i) + "个节点:" + " ");
//
//            for (j = 0; j < MAX_VERTS; j++) {
//                System.out.print(displayVertex(i) + "-" + displayVertex(j) + ": " + LSparse_Matrix.getInstance().getValue(i, j) + " ");
////                        + "：" + adjMat[i][j] + " ");
//            }
//            System.out.println();
//        }

    }

}
